package com.ruoyi.web.controller.pic.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.controller.pic.domain.APic;
import com.ruoyi.web.controller.pic.service.IAPicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 知识图谱管理Controller
 *
 * @author ruoyi
 * @date 2025-05-01
 */
@RestController
@RequestMapping("/pics/pic")
public class APicController extends BaseController
{
    @Autowired
    private IAPicService aPicService;

    /**
     * 查询知识图谱管理列表
     */
    @PreAuthorize("@ss.hasPermi('pics:pic:list')")
    @GetMapping("/list")
    public TableDataInfo list(APic aPic)
    {
        startPage();
        List<APic> list = aPicService.selectAPicList(aPic);
        return getDataTable(list);
    }

    /**
     * 导出知识图谱管理列表
     */
    @PreAuthorize("@ss.hasPermi('pics:pic:export')")
    @Log(title = "知识图谱管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, APic aPic)
    {
        List<APic> list = aPicService.selectAPicList(aPic);
        ExcelUtil<APic> util = new ExcelUtil<APic>(APic.class);
        util.exportExcel(response, list, "知识图谱管理数据");
    }

    /**
     * 获取知识图谱管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('pics:pic:query')")
    @GetMapping(value = "/{picId}")
    public AjaxResult getInfo(@PathVariable("picId") Long picId)
    {

        return success(aPicService.selectAPicByPicId(picId));
    }

    /**
     * 新增知识图谱管理
     */
    @PreAuthorize("@ss.hasPermi('pics:pic:add')")
    @Log(title = "知识图谱管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody APic aPic)
    {
        return toAjax(aPicService.insertAPic(aPic));
    }

    /**
     * 修改知识图谱管理
     */
    @PreAuthorize("@ss.hasPermi('pics:pic:edit')")
    @Log(title = "知识图谱管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody APic aPic)
    {
        return toAjax(aPicService.updateAPic(aPic));
    }

    /**
     * 删除知识图谱管理
     */
    @PreAuthorize("@ss.hasPermi('pics:pic:remove')")
    @Log(title = "知识图谱管理", businessType = BusinessType.DELETE)
	  @DeleteMapping("/{picIds}")
    public AjaxResult remove(@PathVariable Long[] picIds)
    {
        return toAjax(aPicService.deleteAPicByPicIds(picIds));
    }


  @PostMapping("/getNode")
  public  List<Map<String,Object>> getNode(@RequestBody String classId)
  {
    APic aPic = new APic();
    aPic.setClassId(Long.valueOf(classId));
    aPic.setUserId(getUserId());
    List<APic> lists= aPicService.selectAPicList(aPic);
    //格式化node
    List<Map<String,Object>> nodes_list = aPicService.formatNode(lists.get(0).getNodes());

    return nodes_list;
  }

}
